﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MyMaster.Master" AutoEventWireup="true"
    CodeBehind="QuestionNaireDetail.aspx.cs" Inherits="FashionMural.Admin.QuestionNaireDetail" %>

<asp:Content ID="Content1" ContentPlaceHolderID="LeftMenu" runat="server">
    <script type="text/javascript">

        var showflag = true;
        function initAll() {

            //            $("#questionDetailDiv").hide();
            $("#modelInfo").click(
                function () {
                    if (showflag) {
                        $("#modelInfoChild").hide();
                        showflag = false;
                    } else {
                        $("#modelInfoChild").show();
                        showflag = true;
                    }
                }
            );

            var num = getQuestionCount();
            var sepacount = parseInt(num / 3) + 1;
            for (i = 1; i <= sepacount; i++) {
                $("#questiontetailTd").append("<label id='separatepage" + i + "' style='cursor:pointer;text-decoration:underline' onclick=\"showQuestionTable(" + i + ");\">" + i + "</label>&nbsp;&nbsp;");
            }

            showQuestionTable(1);
        }

        function getQuestionCount() {
            var result = 0;
            var date = new Date();
            $.ajax({
                type: "GET",
                async: false,
                url: "/jsserver/question/all/count.aspx",
                success: function (data) {
                    result = 0;
                },
                error: function () {
                    result = 0;
                }
            });
            return result;
        }

        function getQuestion(pagenum) {
            var result = null;
            var date = new Date();
            var index = (pagenum - 1) * 10;
            var count = 3;
            $.ajax({
                type: "GET",
                async: false,
                dataType: "json",
                data: { sindex: index, scount: count, fresh: date.getMilliseconds() },
                url: "/jsserver/question/separete.aspx",
                success: function (data) {
                    result = data;
                },
                error: function () {
                    result = null;
                }
            });
            return result;
        }

        function getUserQuestionAnswer(userid, questionid) {
            var result = null;
            var date = new Date();
            $.ajax({
                type: "GET",
                async: false,
                dataType: "json",
                url: "/jsserver/question/answer.aspx",
                data: { userid: userid, questionid: questionid, fresh: date.getMilliseconds() },
                success: function (data) {
                    result = data;
                },
                error: function () {
                    result = null;
                }
            });
            return result;
        }

        function showQuestionTable(pagenum) {
            var userid = <%=UserId %>;
            var qustions = getQuestion(pagenum);
            if(qustions != null){
            var trs = $("#hide").parent().children();
                if (trs.length > 2) {
                    for (i = 0; i < trs.length - 2; i++) {
                        $(trs[i + 1]).remove();
                    }
                }
                var flag = 0;
                for(i=0;i<qustions.length;i++){
                    var question = qustions[i];
                    if(question != null && question != ""){
                        $("#hide").after("<tr id='questiondetTr"+question.Id+"' style='background-color: #D7D7D7;'><td>"+question.QuestionContent+"</td></tr>");
                    }
                    var answers = getUserQuestionAnswer(userid, question.Id);
                    if(answers != null){                        
                        for(j=0;j<answers.length;j++){
                            var answer = answers[j];
                            if(answer != null && answer != ""){
                                $("#questiondetTr"+question.Id).after("<tr id='answerTr"+flag+"'><td>"+answer+"</td></tr>");
                                flag = flag+1;
                            }else{
                                $("#questiondetTr"+question.Id).after("<tr id='answerTr"+flag+"'><td>&nbsp;</td></tr>");
                                flag=flag+1;
                            }
                        }
                        if(answers.length == 0){
                        $("#questiondetTr"+question.Id).after("<tr id='answerTr"+flag+"'><td>&nbsp;</td></tr>");
                        flag=flag+1;
                        }                        
                    }else{
                        $("#questiondetTr"+question.Id).after("<tr id='answerTr"+flag+"'><td>&nbsp;</td></tr>");
                        flag=flag+1;
                    }
                    $("#answerTr"+(flag-1)).after("<tr><td style='text-align:center;'>----------------------------</td></tr>");
                }
            }

            $("#separatepage"+pagenum).attr("style", "font-size:15px;color:Red;cursor:pointer;");
        }

        $().ready(function () {
            initAll();
        });
    </script>
    <div class="leftMenuTitle" id="modelInfo" style="cursor: pointer;">
        模块信息
    </div>
    <ul class="leftMenu" id="modelInfoChild">
        <li><a href="/ModelManage.aspx">用户留言</a></li>
        <li><a href="/ModelManage.aspx">加盟留言</a></li>
        <li><a href="/ModelManage.aspx">友情链接</a></li>
        <li><a href="/QuestionNaire.aspx">问卷调查</a></li>
    </ul>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MidContent" runat="server">
    <div id="mainMenu">
        <ul>
            <li><a id="showcurrent" href="#"></a></li>
        </ul>
    </div>
    <div id="main">
        <table id="questiontetail" class="mainTable">
            <tr id='hide' style="visibility: hidden">
                <td>
                </td>
            </tr>
            <tr>
                <td id="questiontetailTd" style="text-align: center;">
                </td>
            </tr>
        </table>
    </div>
</asp:Content>
